package it.infodea.tapestrydea.entities.demo;

import it.infodea.tapestrydea.support.interfaces.Identifiable;

import org.apache.tapestry5.beaneditor.NonVisual;
import org.apache.tapestry5.beaneditor.Validate;

public class UserBean implements Identifiable {

	@NonVisual
	private Long id;

	@Validate("required")
	private String firstName;

	@Validate("required")
	private String lastName;

	@Validate("required")
	private int age;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@NonVisual
	public Object getDisplayId() {
		return getFirstName() + " " + getLastName();
	}

	@NonVisual
	public String getIdValue() {
		return getId() == null ? null : getId().toString();
	}

	public void setIdValue(Object idValue) {
		setId((Long) idValue);
	}

	public static UserBean newInstance(String firstName, String lastName, int age, long id) {
		UserBean user = new UserBean();
		user.setFirstName(firstName);
		user.setLastName(lastName);
		user.setAge(age);
		user.setId(id);
		return user;
	}

}
